import store from '../store/index.js'
export default function $http(options) {
	const {
		url,
		data
	} = options
	const data_obj = {
		user_id: store.state.userinfo._id,
		user_typs: store.state.userinfo._typs,
		...data
	}
	return new Promise((reslove, reject)=>{
		uniCloud.callFunction({
			name: url,
			data: data_obj
		}).then((res)=>{
			if (res.result.code !== 200) {
				uni.showToast({ title: res.result.msg, icon: 'error' })
				setTimeout(function () { uni.hideLoading() }, 2000);
			} else {
				reslove(res.result)
			}
		}).catch((err)=>{
			uni.showToast({ title: '程序错误.', icon: 'error' })
			setTimeout(function () { 
				uni.reLaunch({
					url: '/pages/login/login'
				})
			}, 2000);
			reject(err)
		})
	})
}